import { cloneObject } from '@/lib/util'
import { Base } from './base'

type FileRef = {
  src: string
  length: number
  in: number
  out: number
  id: string
}
export class Clip extends Base {
  id: string
  name: string
  offset: number
  start: number
  tcFormat: string
  duration: number
  ref?: FileRef
  src?: string
  thumbnail?: string
  format: string
  type: number
  constructor(meta: any) {
    super()
    this.name = meta.name
    this.offset = meta.offset
    this.start = meta.start
    this.tcFormat = meta.tcFormat
    this.duration = meta.duration
    this.ref = meta.ref
    this.format = meta.format
    this.id = meta.id
    this.src = meta.src // 暂时用src
    this.thumbnail = meta.thumbnail
    this.type = 1
  }
  toJson() {
    return this
    // return {
    //   name: this.name,
    //   id: this.id,
    //   file: {
    //     url: this.ref?.src,
    //   },
    //   type: this.type,
    //   in: this.ref?.in,
    //   out: this.ref?.out,
    //   start: this.offset,
    //   end: this.offset + this.duration,
    // }
  }
  clone() {
    return new Clip(cloneObject(this))
  }
}
